package org.crown.kings.jsf.formatters.en_US;

import org.crown.kings.jsf.formatters.en_US.PhoneNumberBeanFormatterImpl.PhoneNumberFormat;
import org.junit.Test;
import static junit.framework.Assert.*;

public class PhoneNumberBeanFormatterImplTests
{

	@Test
	public void testSetFormat()
	{
		String expected = "nnn.nnn.nnnn";	
		assertEquals(expected, PhoneNumberFormat.DOTS, PhoneNumberFormat.parseFormat(expected));
		expected = "(nnn) nnn-nnnn";
		assertEquals(expected, PhoneNumberFormat.BASIC, PhoneNumberFormat.parseFormat(expected));
		expected = "nnn-nnn-nnnn";
		assertEquals(expected, PhoneNumberFormat.DASHES, PhoneNumberFormat.parseFormat(expected));
	}
	
	@Test(expected=IllegalArgumentException.class)
	public void testSetFormat_Null()
	{
		assertNotNull("Expected exception with null parameter", PhoneNumberFormat.parseFormat(null));
	}
	
	@Test(expected=IllegalArgumentException.class)
	public void testSetFormat_BadFormat()
	{
		assertNotNull("Expected exception with null parameter", PhoneNumberFormat.parseFormat("moo"));
	}
	
	@Test
	public void testBasicFormat()
	{
		String expected = "(123) 456-7890";
		
		assertEquals(expected, PhoneNumberBeanFormatterImpl.formatNumber(PhoneNumberFormat.BASIC, "1234567890"));
		assertEquals(expected, PhoneNumberBeanFormatterImpl.formatNumber(PhoneNumberFormat.BASIC, "123.456.7890"));
		assertEquals(expected, PhoneNumberBeanFormatterImpl.formatNumber(PhoneNumberFormat.BASIC, "123-456-7890"));
		assertEquals(expected, PhoneNumberBeanFormatterImpl.formatNumber(PhoneNumberFormat.BASIC, "(123) 456.7890"));
		// Finally, if the number is completely off-base, it should silently return the original value.
		assertEquals("moo", PhoneNumberBeanFormatterImpl.formatNumber(PhoneNumberFormat.BASIC, "moo"));
		assertEquals(null, PhoneNumberBeanFormatterImpl.formatNumber(PhoneNumberFormat.BASIC, null));
		
		
	}
	
}
